package org.miyuki4j.cfgtool;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Desc
 * @Author miyuki4j
 * @Date 2025/7/24/星期四 17:04
 * @Version 1.0
 */
public class TableDataRow implements Iterable<TableDataCell> {
    private final int row;
    private final List<TableDataCell> cells = new ArrayList<>();

    public TableDataRow(int row) {
        this.row = row;
    }

    public TableDataRow() {
        this.row = -1;
    }

    public void add(TableDataCell cell) {
        cells.add(cell);
    }

    public int getRow() {
        return row;
    }

    public List<TableDataCell> getCells() {
        return cells;
    }

    @Override
    public Iterator<TableDataCell> iterator() {
        return cells.iterator();
    }

    /**
     * 判断行内容是否为空
     *
     * @return
     */
    public boolean isContentEmpty() {
        if (cells.isEmpty()) {
            return true;
        }
        for (TableDataCell cell : this) {
            if (!StringUtils.trim(cell.getValue()).isEmpty()) {
                return false;
            }
        }
        return true;
    }

    @Override
    public String toString() {
        return "TableDataRow{" +
                "row=" + row +
                ", cells=" + cells +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;

        TableDataRow that = (TableDataRow) o;
        return row == that.row && cells.equals(that.cells);
    }

    @Override
    public int hashCode() {
        int result = row;
        result = 31 * result + cells.hashCode();
        return result;
    }
}
